package mg2d.domain;


public class TriangularMesh implements Domain {
	private int n;
	public TriangularMesh(int n) {
		this.n = n;
	}

	@Override
	public double x(int i, int j, int level) {
		final double deltaX = 2.0*Math.sqrt(3.0)/(3.0*levelN(level));
		final double deltaY = 1.0/levelN(level);
		return (-j*deltaY/Math.sqrt(3.0)) + i*deltaX;
	}

	@Override
	public double y(int i, int j, int level) {
		final double deltaY = 1.0/levelN(level);
		return j*deltaY;
	}
	
	public int levelN(int level){
		if(level==0)
			return n;
		return n/(2 << (level-1) );
	}
}
